import { Inject, Controller, Get, Post, Param} from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { IdleService } from '../../service/admin/idle.service';
import * as fs from 'fs';
import * as path from 'path';


@Controller('/api/admin')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  idleService: IdleService;
  

  @Get('/getAllidle', { description: '获得所有闲置' })
  async getidle() {
    const result = await this.idleService.getidle()
    if(result.length!=0){
      for(var i = 0 ;i< result.length; i++){
        const fileName = result[i].image;
        const idlepic = fs.readFileSync(path.join(__dirname, '../../../public/upload/idle', fileName));
        result[i]["src"] = idlepic  
        result[i]["type"] = "闲置"      
      } 
    }
    return { success: true, message: '闲置查询成功', result }
  }

  @Post('/deleteidle/:id', { description: '删除闲置' })
  async Param(@Param() Param) {
      const result = await this.idleService.deleteidle(Param.id)
      return { success: true, message: '删除成功', result }
  }

}